﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Views;
using NLBS.Entity;
using System.Web;
using NLBS.Data.Business;

namespace NLBS.Web.UI
{
    public class TrackBackCommand : ICommand, IAction<TrackBack>
    {
        #region Presenter

        private TrackBackPresenter _presenter;

        public TrackBackPresenter Presenter
        {
            get
            {
                if (this._presenter == null)
                    _presenter = new TrackBackPresenter();
                this._presenter.Action = this;
                return _presenter;
            }
        }

        private void PresenterInit()
        {
            this.Presenter.OnActionLoaded();
        }
        #endregion

       private Action act;
       private CallBackBase callback;
       private HttpRequest request;
       
       public TrackBackCommand(Action act, CallBackBase callBack)
       {
           this.act = act;
           this.callback = callBack;
       }

        #region ICommand Members

        public void Excute()
        {
            request = callback.Page.Request;
            PresenterInit();
            switch (act)
            {
                case Action.Insert:
                    //InsertAction();
                    break;
                case Action.Delete:
                    DeleteAction();
                    break;
                case Action.DeleteMulit:
                    DeleteMulitTrackback();
                    break;
            }
           
        }

        private void DeleteAction()
        {
            this.keyID = Convert.ToInt32(request.Form["id"]);
            this.DataDelete(null, null);
        }

        private void DeleteMulitTrackback()
        {
            string[] Ids = request.Form["Ids"].Split(new char[] { ',' });
            foreach (string item in Ids)
            {
                this.keyID = int.Parse(item);
                this.DataDelete(null, null);
            }
        }

        #endregion

        #region IAction<TrackBack> Members
        private TrackBack _entity;
        public TrackBack Entity
        {
            get
            {
                return _entity;
            }
            set
            {
                _entity = value;
            }
        }

        private int _keyID;
        public int keyID
        {
            get
            {
                return _keyID;
            }
            set
            {
                _keyID = value;
            }
        }

        public event EventHandler DataInsert;

        public event EventHandler DataUpdate;

        public event EventHandler DataDelete;

        public event EventHandler DataSelectSingle;

        #endregion
    }
}
